package com.cupk.controller;

import com.cupk.pojo.Result;
import com.cupk.utils.COSUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
public class FileController {
    @PostMapping("/file/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String ext = originalFilename.substring(originalFilename.lastIndexOf("."),originalFilename.length());
        String contentType = file.getContentType();
        // String filename = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
        String fileURL = COSUtil.upLoad(file.getInputStream(),ext,contentType);
        // String fileload = System.getProperty("user.dir") + "\\files\\";
        // file.transferTo(new File(fileload + filename));
        return Result.success(fileURL);
    }
}
